#include "gmock.h"

#include "Logger.h"
#include <locale>

class NormalCaller
{
public:
	virtual size_t strlen(const char* s) = 0;
};

class CCaller: public NormalCaller
{
public:
	virtual size_t strlen(const char* a) { return ::strlen(a) ;}
};


class MockCaller : public CCaller
{public:
	MOCK_METHOD1(strlen,size_t(const char*));
};

CCaller globalcaller;
NormalCaller* c = &globalcaller;
class temp
{
public :
	size_t test()

	{
		char r[2048] = {'\0'};
		return c->strlen(r);
	}
	template <typename E> std::string testingvec(E* ptr)
	{

		std::cout << std::endl << ptr->name() << std::endl; return ptr->name();
	}
};

class NonVirtualMethods
{ public:
	virtual std::string name() const = 0;
};





class MockNonVirtualMethods
{
public :
	MOCK_CONST_METHOD0(name,std::string());
};

TEST(MOCKTEST,NORMALTEST)
{
	MockCaller obj;

	temp object;
	::c = & obj;
	EXPECT_CALL(obj,strlen(::testing::SafeMatcherCast<const char*>(::testing::_))).WillOnce(::testing::Return(1));
	EXPECT_TRUE( object.test() == 1);
	std::locale loc;
	EXPECT_TRUE(object.testingvec(&loc) == loc.name());

	MockNonVirtualMethods o;
	EXPECT_CALL(o,name()).WillRepeatedly(::testing::Return("NO"));

	EXPECT_TRUE(object.testingvec(&o) == "NO");
}
